package com.yunji.base.business;

import com.yunji.base.bo.ChangeBindBO;
import com.yunji.base.bo.StaffSiteRemoveBO;
import com.yunji.base.business.common.SiteAuditCommonBusiness;
import com.yunji.base.consumer.BaseDataConsumer;
import com.yunji.base.cache.BaseCache;
import com.yunji.base.domain.*;
import com.yunji.base.dto.*;
import com.yunji.base.engine.validate.SiteValidate;
import com.yunji.base.enums.AgentMode;
import com.yunji.base.enums.ScaleTypes;
import com.yunji.base.enums.SwitchStatus;
import com.yunji.base.service.*;
import com.yunji.base.vo.SiteInfoVO;
import com.yunji.cabinet.bo.CabinetBO;
import com.yunji.cabinet.bo.CabinetListQueryBO;
import com.yunji.cabinet.domain.ContainerCell;
import com.yunji.common.constant.Constants;
import com.yunji.common.constant.LogicCode;
import com.yunji.common.enums.common.UserType;
import com.yunji.common.model.cache.ProductCacheDTO;
import com.yunji.common.model.domain.SiteDO;
import com.yunji.common.model.domain.StaffDO;
import com.yunji.common.model.domain.SysUserDO;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.utils.DecimalUtils;
import com.yunji.common.utils.StringUtils;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.product.bo.ProductAgentListQueryBO;
import com.yunji.product.cache.ProductCache;
import com.yunji.product.domain.ProductAgentDO;
import com.yunji.system.context.SystemContext;
import com.yunji.system.context.SystemUtil;
import com.yunji.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.user.business
 * @FileName SiteBusiness.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-05-28 16:01:48
 * @Description 网点业务处理
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-05-28 16:01:48		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Slf4j
@Component
public class SiteBusiness {

    private static final String PARAM_PRODUCT_AGENT = "product_agent";
    @Resource
    private BaseDataConsumer baseDataConsumer;
    @Resource
    private SiteService siteService;
    @Resource
    private SiteAuditCommonBusiness siteAuditCommonBusiness;
    @Resource
    private StaffSiteService staffSiteService;
    @Resource
    private StaffService staffService;
    @Resource
    private ISysUserService sysUserService;
    @Resource
    private ISysUserService userService;
    @Resource
    private BelongService belongService;
    @Resource
    private ManagerSiteService managerSiteService;
    @Resource
    private AgentSiteService agentSiteService;
    @Resource
    private AgentService agentService;
    @Resource
    private ManagerService managerService;

    /**
     * @param id 网点D
     * @Title select
     * @Desc 获取网点信息
     * @Date 2024-05-28 17:40:03.901
     * @Return SiteInfo 网点信息
     */
    public SiteInfoVO getSiteInfoVO(Long id) {
        return siteService.getSiteInfoVO(id);
    }

    /**
     * @param dto 上送信息
     * @Title create
     * @Desc 创建网点信息
     * @Date 2024-05-30 14:12:26.744
     */
    @Transactional
    public Long create(SiteDTO dto) {
        // 校验网点手机号是否唯一
        SiteValidate.validatePhone(dto.getSiteTel());
        //校验网点基础参数
        SiteValidate.validateSiteParam(dto);
        //校验网点所属参数
        siteAuditCommonBusiness.checkSite(dto);
        Integer agentMode = dto.getCooperateWay();
        /*--------------------------------------------*
         * 自营代理走审核 非自营走正常流程
         * 1、自营
         * 1.1、在免审范围之外 审核列表
         * 1.2、在免审范围之内 免审
         * 2、非自营代理
         * 直接走新增
         *--------------------------------------------*/
        //不需要审核
        if (!BeanUtils.equals(agentMode, AgentMode.SELF_SUPPORT.getCode())) {
            return siteAuditCommonBusiness.handleAgentSupport(dto);
        }
        //需要审核
        return siteAuditCommonBusiness.handleCreateSite(dto);
    }

    /**
     * @param dto 上送信息
     * @Title update
     * @Desc 更新网点信息
     * @Date 2024-05-30 14:12:44.441
     */
    @Transactional
    public void update(SiteDTO dto) {
        SiteValidate.validateSiteParam(dto);
        siteAuditCommonBusiness.checkSite(dto);
        Long siteId = dto.getId();
        log.info("【修改网点】网点ID:{}", siteId);
        SiteDO site = siteService.getById(siteId);
        Assert.isTrue(BeanUtils.isNotNull(site), SiteAuditCommonBusiness.NOT_FIND_SITE);
        dto.set(SiteAuditCommonBusiness.PARAM_SITE, site);

        Integer agentMode = dto.getCooperateWay();
        String agentText = AgentMode.get(agentMode);
        log.info("【修改网点】代理合作方式={}:{}", agentMode, agentText);

        siteAuditCommonBusiness.handleUpdateSite(dto);
    }

    /**
     * @param ids 网点ID数组
     * @Title delete
     * @Desc 删除网点信息
     * @Date 2024-05-28 19:59:10.368
     */
    @Transactional
    public void delete(Long... ids) {
        // 网点绑定了员工无法删除
        Assert.isTrue(!BeanUtils.isNotNull(staffSiteService.listBySiteIds(Arrays.asList(ids))), "网点绑定了员工");

        // 网点绑定了货柜
        Assert.isTrue(!BeanUtils.isNotNull(baseDataConsumer.searchCSBySiteIds(ids)), "网点绑定了货柜");

        // 网点有订单数据不能删除
        Assert.isTrue(!baseDataConsumer.existsOrderBySiteIds(Arrays.asList(ids)), "网点有售卖数据");

        List<SiteDO> list = siteService.search(ids);
        Map<Long, Long> siteSets = list.stream().collect(Collectors.toMap(SiteDO::getBelongId, SiteDO::getBelongId, (k1, k2) -> k1));
        Set<Long> belongIds = siteSets.keySet();

        List<ManagerSiteDO> managerSite = managerSiteService.selectBySiteId(ids);
        log.info("【网点信息】停用用户网点绑定信息");
        Assert.isTrue(managerSiteService.deleteBySiteId(ids), SiteAuditCommonBusiness.NOT_FIND_MANAGER);

        List<Long> userIds = managerSite.stream().map(ManagerSiteDO::getManagerId).collect(Collectors.toList());
        log.info("【网点信息】停用用户信息,用户ID信息{}", userIds);
        //FIXME 删除审核网点信息

        baseDataConsumer.deletePAByManagerIds(ids);

        Long[] managerIds = userIds.toArray(new Long[0]);

        Assert.isTrue(managerService.deleteByUserId(managerIds), "删除网点用户信息失败");
        Assert.isTrue((userService.deleteUserByIds(managerIds) > 0), "停用账户失败");
        Assert.isTrue(agentSiteService.deleteBySiteIds(ids), "删除失败");
        Assert.isTrue(siteService.delete(ids), "删除失败");
        Assert.isTrue(belongService.delete(belongIds), "删除失败");
    }

    /**
     * @param dto 网点信息
     * @Title bindStaffSite
     * @Desc 员工网点绑定 (建议保留)
     * @Date 2024-05-30 14:11:49.746
     */
    @Transactional
    public void bindStaffSite(SiteStaffDTO dto) {
        Long siteId = dto.getSiteId();
        log.info("【站点绑定员工】网点ID:{}", siteId);
        Assert.isTrue(BeanUtils.isNotNull(siteId), "未找到站点信息");

        Long[] staffIds = dto.getStaffId();
        Assert.isTrue(BeanUtils.isNotNull(staffIds), "员工不存在");
        List<StaffDO> list = staffService.listByStaffIds(Arrays.asList(staffIds));
        Map<Long, StaffDO> map = list.stream().collect(Collectors.toMap(StaffDO::getId, staff -> staff, (k1, k2) -> k1));

        Assert.isTrue(staffSiteService.remove(StaffSiteRemoveBO.builder().siteId(siteId).build()), "绑定失败");

        List<StaffSiteDO> staffSiteList = new ArrayList<>();
        for (Long staffId : staffIds) {
            Assert.isTrue(map.containsKey(staffId), "员工不存在");

            StaffSiteDO staffSite = new StaffSiteDO();
            staffSite.setSiteId(siteId);
            staffSite.setStaffId(staffId);
            staffSiteList.add(staffSite);
        }
        Assert.isTrue(staffSiteService.insertTStaffSiteByList(staffSiteList), "绑定员工失败");
    }

    /**
     * @param productAgent 原始价格
     * @Title handleDiscountPrice
     * @Desc 处理代理商品价格信息
     * @Date 2024-09-13 09:45:17.731
     * @Return BigDecimal 折扣价格
     */
    private BigDecimal handleDiscountPrice(ProductAgentDO productAgent) {
        BigDecimal discountPrice = BeanUtils.getDecimal(productAgent.getDiscountPrice());
        BigDecimal agentPrice = BeanUtils.getDecimal(productAgent.getAgentPrice());
        log.info("【自定义价格】原授权商品价格:{},代理商商品价格:{}", discountPrice, agentPrice);
        if (DecimalUtils.compare(agentPrice)) {
            return discountPrice;
        }

        ProductCacheDTO product = ProductCache.getProduct(productAgent.getProductId());
        //现商品最大折扣价
        BigDecimal maxDiscountPrice = product.getMaxDiscountPrice();
        log.info("【自定义价格】现商品最大折扣价：{}", maxDiscountPrice);
        //现商品最小折扣价
        BigDecimal minDiscountPrice = product.getMinDiscountPrice();
        log.info("【自定义价格】现商品最小折扣价：{}", minDiscountPrice);

        discountPrice = DecimalUtils.less(discountPrice, minDiscountPrice) ? minDiscountPrice : discountPrice;
        discountPrice = DecimalUtils.more(discountPrice, maxDiscountPrice) ? maxDiscountPrice : discountPrice;
        log.info("【自定义价格】商品最终折扣价：{}", discountPrice);
        return discountPrice;
    }

    /**
     * @param dto 网点定价信息
     * @Title customPrice
     * @Desc 变更网点定价信息
     * @Date 2024-06-05 14:52:03.769
     */
    @Transactional
    public void customPrice(SiteDTO dto) {
        Long siteId = dto.getId();
        log.info("【自定义价格】网点ID:{}", siteId);
        SiteDO site = siteService.getById(siteId);
        log.info("【自定义价格】网点信息:{}", site);
        Assert.isTrue(BeanUtils.isNotNull(site), SiteAuditCommonBusiness.NOT_FIND_SITE);

        Long belongId = site.getBelongId();
        log.info("【自定义价格】网点所属ID:{}", belongId);
        BelongDO belong = BaseCache.getBelong(belongId);
        log.info("【自定义价格】网点所属:{}", belong);
        Assert.isTrue(BeanUtils.isNotNull(belong), SiteAuditCommonBusiness.NOT_FIND_SITE);

        Long parentId = belong.getParentId();
        log.info("【自定义价格】代理所属ID:{}", parentId);

        Integer customPrice = dto.getCustomPrice();
        String text = SwitchStatus.get(customPrice);
        log.info("【自定义价格】定价={}:{}", customPrice, text);
        Assert.isTrue(BeanUtils.isNotNull(customPrice), "请上送定价信息");

        List<ManagerSiteDO> list = managerSiteService.selectBySiteId(siteId);
        Assert.isTrue(BeanUtils.isNotNull(list), SiteAuditCommonBusiness.NOT_FIND_MANAGER);

        ManagerSiteDO managerSite = list.get(0);
        Long managerId = managerSite.getManagerId();
        log.info("【自定义价格】网点用户ID:{}", managerId);
        Assert.isTrue(BeanUtils.isNotNull(managerId), SiteAuditCommonBusiness.NOT_FIND_MANAGER);

        // 如果关闭定价就将自定义的价格改为代理商的定价
        ProductAgentListQueryBO productAgent = new ProductAgentListQueryBO();
        productAgent.setBelongId(parentId);
        List<ProductAgentDO> productAgents = baseDataConsumer.searchProductAgent(productAgent);
        if (BeanUtils.isNull(productAgents)) {
            return;
        }

        productAgent.setBelongId(belongId);
        List<ProductAgentDO> productSites = baseDataConsumer.searchProductAgent(productAgent);
        if (BeanUtils.isNull(productSites)) {
            return;
        }

        Map<Long, ProductAgentDO> map = productSites.stream().collect(Collectors.toMap(ProductAgentDO::getProductId, o -> o, (k1, k2) -> k1));

        // 开启授权  先看自定义价格 没有 就跟着 授权价走
        for (ProductAgentDO agentProductPrice : productAgents) {
            Long productId = agentProductPrice.getProductId();
            if (!map.containsKey(productId)) {
                continue;
            }

            ProductAgentDO siteProductPrice = map.get(productId);
            BigDecimal price = handleDiscountPrice(siteProductPrice);

            ProductAgentDO productManager = new ProductAgentDO();
            productManager.setId(siteProductPrice.getId());
            productManager.setDiscountPrice(price);
            productManager.setProductId(productId);
            productManager.setUserType(UserType.SITE.getCode());
            productManager.setSiteId(siteId);
            baseDataConsumer.updateProductAgent(productManager);
        }

        deleteUserToken(belongId);

        ManagerDO updateManager = new ManagerDO();
        updateManager.setManagerId(managerId);
        updateManager.setCustomPrice(customPrice);
        Assert.isTrue(managerService.customPriceByManagerId(managerId, customPrice), SiteAuditCommonBusiness.CUSTOM_PRICE_FAILURE);

        BelongDO updateBelong = new BelongDO();
        updateBelong.setBelongId(belongId);
        updateBelong.setCustomPrice(customPrice);
        Assert.isTrue(belongService.update(updateBelong), SiteAuditCommonBusiness.CUSTOM_PRICE_FAILURE);
    }

    /**
     * @param dto 更换代理信息
     * @Title changeBind
     * @Desc 网点更换代理
     * @Date 2024-08-22 11:42:10.882
     */
    @Transactional
    public void changeBind(ChangeBindDTO dto) {
        Long agentId = dto.getAgentId();
        log.info("【更换代理】新代理ID:{}", agentId);
        AgentDTO agentDTO = agentService.select(agentId);

        log.info("【更换代理】新代理信息：{}", agentDTO);
        Assert.isTrue(BeanUtils.isNotNull(agentDTO), "未找到新代理信息");
        String agentName = agentDTO.getAgentName();

        Long siteId = dto.getSiteId();
        log.info("【更换代理】网点ID：{}", siteId);
        SiteDO siteInfo = siteService.getById(siteId);

        log.info("【更换代理】网点信息：{}", siteInfo);
        Assert.isTrue(BeanUtils.isNotNull(siteInfo), SiteAuditCommonBusiness.NOT_FIND_SITE);

        Long belongId = siteInfo.getBelongId();
        Long parentId = agentDTO.getBelongId();
        log.info("【更换代理】网点属组：{},代理属组：{}", belongId, parentId);
        dto.setBelongId(belongId);
        dto.setParentId(parentId);

        ManagerSiteDO managerSite = managerSiteService.getBySiteId(siteId);
        log.info("【更换代理】网点经理用户绑定：{}", managerSite);
        Assert.isTrue(BeanUtils.isNotNull(managerSite), "未找到网点关联经理用户信息");
        Long managerId = managerSite.getManagerId();
        dto.setManagerId(managerId);

        BindRecordDO bindRecord = new BindRecordDO();
        bindRecord.setAgentId(agentId);
        bindRecord.setSiteId(siteId);

        // 校验分润
        handleChangeScale(agentDTO, dto);

        checkProductAuth(dto);

        baseDataConsumer.deletePAByManagerIds(siteId);

        List<ProductAgentDO> newProductAgent = dto.get(PARAM_PRODUCT_AGENT);
        siteAuditCommonBusiness.createSiteProduct(newProductAgent, belongId, siteId);

        // 处理代理网点绑定
        AgentSiteDO agentSiteParam = new AgentSiteDO();
        agentSiteParam.setSiteId(siteId);
        List<AgentSiteDO> agentSiteList = agentSiteService.search(agentSiteParam);
        Assert.isTrue(BeanUtils.isNotNull(agentSiteList), "未找到网点旧代理绑定信息");
        log.info("【更换代理】网点旧代理绑定信息：{}", agentSiteList.get(0));
        Assert.isTrue(agentSiteService.delete(agentSiteList.get(0).getId()), "删除失败");

        agentSiteParam.setAgentId(agentId);
        Assert.isTrue(agentSiteService.create(agentSiteParam), "新增失败");
        log.info("【更换代理】网点新代理绑定信息：{}", agentSiteParam);

        // 处理经理用户
        ManagerDO manager = managerService.select(managerId);
        Assert.isTrue(BeanUtils.isNotNull(manager), "未找到经理用户信息");

        bindRecord.setPreviousAgentId(manager.getAgentId());
        log.info("【更换代理】经理用户信息：{}", manager);

        manager.setAgentId(agentId);
        Integer scaleType = dto.getScaleType();
        manager.setScaleType(scaleType);
        BigDecimal scaleRatio = BeanUtils.getDecimal(dto.getScale());
        manager.setScale(scaleRatio);
        manager.setCustomPrice(SwitchStatus.DISABLE.getCode());
        Assert.isTrue(managerService.update(manager), "修改失败");

        Map<String, Object> map = new HashMap<>();
        map.put("siteId", siteId);
        map.put("agentId", agentId);
        map.put("belongId", belongId);
        map.put("agentName", agentName);

        baseDataConsumer.changeTemplateAgent(ChangeBindBO.builder().agentId(agentId).belongId(belongId).siteId(siteId).agentName(agentName).build());

        baseDataConsumer.changeCabinetAgent(ChangeBindBO.builder().agentId(agentId).belongId(belongId).siteId(siteId).agentName(agentName).build());

        staffService.changeAgent(ChangeBindBO.builder().agentId(agentId).belongId(belongId).siteId(siteId).agentName(agentName).build());

        bindRecord.setManagerId(managerId);
        Assert.isTrue(siteService.createBindRecord(bindRecord), "新增失败");

        SiteDO site = new SiteDO();
        site.setId(siteId);
        site.setBelongId(belongId);

        BelongDO belong = new BelongDO();
        belong.setBelongId(belongId);
        belong.setParentId(parentId);
        belong.setAgentId(agentId);
        belong.setScaleType(scaleType);
        belong.setScaleRatio(scaleRatio);

        deleteUserToken(belongId);

        Assert.isTrue(userService.updateUserBelong(managerId, belongId), "更换失败");
        Assert.isTrue(siteService.update(site), "更换失败");
        Assert.isTrue(belongService.update(belong), "更换失败");


    }

    /**
     * @Title currentStaffSite
     * @Desc 当前员工绑定网点信息
     * @Date 2024-09-11 17:09:11.819
     * @Return List<Site> 网点信息
     */
    public List<SiteDO> currentStaffSite() {
        LoginInfo user = SystemContext.getUser();
        Assert.isTrue(BeanUtils.isNotNull(user), "请先登录后操作");
        Long userId = user.getUserId();
        log.info("【员工网点】当前员工网点ID:{}", userId);
        return siteService.selectSitesByStaffId(userId);
    }

    /*------------------------------------------非接口------------------------------------------*/

    /**
     * @param belongId 网点所属ID
     * @Title deleteUserToken
     * @Desc 删除网点登录Token
     * @Date 2024-11-11 14:26:10.660
     */
    private void deleteUserToken(Long belongId) {
        // 找到当前belongId的用户 退出登录
        SysUserDO userParam = new SysUserDO();
        userParam.setBelongId(belongId);
        List<SysUserDO> userList = sysUserService.searchUserList(userParam);
        for (SysUserDO user : userList) {
            String redisToken = StringUtils.format(Constants.REDIS_BELONG_UUID, belongId) + user.getUserId();
            if (SystemUtil.redisCache().hasKey(redisToken)) {
                String uuid = SystemUtil.redisCache().get(redisToken);
                SystemUtil.redisCache().delete(uuid);
                SystemUtil.redisCache().delete(redisToken);
            }
        }
    }

    /**
     * @param agentDTO 原始代理信息
     * @param dto      换绑信息
     * @Title handleChangeScale
     * @Desc 处理换绑分润信息
     * @Date 2024-09-13 09:48:27.716
     */
    private void handleChangeScale(AgentDTO agentDTO, ChangeBindDTO dto) {
        Integer agentMode = agentDTO.getCooperateWay();
        String modelText = AgentMode.get(agentMode);
        Integer scaleType = dto.getScaleType();
        String scaleText = ScaleTypes.get(dto.getScaleType());
        log.info("【校验分润】合作模式={}:{},分润方式={}:{},", agentMode, modelText, scaleType, scaleText);

        BigDecimal agentScale = BeanUtils.getDecimal(agentDTO.getAgentScale());
        BigDecimal scale = BeanUtils.getDecimal(dto.getScale());
        log.info("【校验分润】代理分润比例:{},网点分润比例:{}", agentScale, scale);

        // 代理  校验是否达到 代理最高分润   不能超过代理分润
        // 自营  校验是否超出平台限制配置最高分润比列   如果 加起来不能打过百分百
        if (!BeanUtils.equals(ScaleTypes.RATIO.getCode(), scaleType)) {
            return;
        }

        if (BeanUtils.equals(AgentMode.AGENT_SUPPORT.getCode(), agentMode)) {
            Assert.isTrue(!DecimalUtils.more(scale, agentScale), "网点分润比例不能大于代理分润比例");
        } else {
            Assert.isTrue(!DecimalUtils.more(scale.add(agentScale), new BigDecimal("100")), "网点分润不合规");
        }
    }

    /**
     * @param dto 切换信息
     * @Title checkProductAuth
     * @Desc 检查商品权限
     * @Date 2024-09-14 18:25:13.759
     */
    private void checkProductAuth(ChangeBindDTO dto) {
        // 先查出来代理的所有商品授权
        // 再查出来网点的所有商品授权
        // 进行比对
        // 停掉之前的授权 新增现代理的商品授权
        // 和新增网点商品授权逻辑一样
        Long agentId = dto.getAgentId();
        Long siteId = dto.getSiteId();
        log.info("【更换代理】新代理ID:{},网点ID：{}", agentId, siteId);

        ProductAgentListQueryBO params = new ProductAgentListQueryBO();
        params.setAgentId(agentId);
        params.setUserType(UserType.AGENT.getCode());
        params.setStatus(LogicCode.NO);
        List<ProductAgentDO> newProductAgent = baseDataConsumer.searchProductAgent(params);
        Assert.isTrue(BeanUtils.isNotNull(newProductAgent), "未找到代理授权商品");
        dto.set(PARAM_PRODUCT_AGENT, newProductAgent);

        // 获取货柜的商品信息
        List<CabinetBO> cabinetList = baseDataConsumer.searchCabinetList(CabinetListQueryBO.builder().siteId(siteId).build());
        if (BeanUtils.isNull(cabinetList)) {
            return;
        }

        List<ContainerCell> cells = new ArrayList<>();
        cabinetList.forEach(cabinet -> cells.addAll(cabinet.getCellList()));
        Assert.isTrue(BeanUtils.isNotNull(cells), "未找到货柜格子信息");
        List<Long> useProductIds = cells.stream().map(ContainerCell::getProductId).distinct().collect(Collectors.toList());

        Map<String, ProductAgentDO> map = newProductAgent.stream().collect(Collectors.toMap(k -> k.getProductId() + "_" + k.getStatus(), e -> e, (k1, k2) -> k1));

        boolean flag = true;
        StringBuilder build = new StringBuilder();
        for (Long productId : useProductIds) {
            String key = productId + "_" + 0;
            if (map.containsKey(key)) {
                continue;
            }
            build.append("商品【");
            build.append(ProductCache.getProductName(productId));
            build.append("】未被授权");
            flag = false;
        }
        Assert.isTrue(flag, build.toString());
    }

    /**
     * ------------------------------------------搜索栏------------------------------------------
     */

    public List<String> searchName(String name) {
        Assert.isTrue((name.length() <= 15), "输入的网点名称不合规");
        SiteFieldDTO param = new SiteFieldDTO();
        param.setSiteName(name);
        param.setSearchFiled("site_name");
        List<String> response = siteService.searchTableFiled(param);
        return BeanUtils.isNotNull(response) ? response : Collections.emptyList();
    }

    public List<String> searchPhone(String phone) {
        Assert.isTrue(phone.matches("^\\d{0,11}$"), "输入的网点电话不合规");
        SiteFieldDTO param = new SiteFieldDTO();
        param.setSiteTel(phone);
        param.setSearchFiled("site_tel");
        List<String> response = siteService.searchTableFiled(param);
        return BeanUtils.isNotNull(response) ? response : Collections.emptyList();
    }
}
